package org.example.memo;
//https://leetcode.cn/problems/longest-increasing-subsequence/
//300. 最长递增子序列
class Solution {
    //记忆化搜索
    int ret = 1;
    int path;
    int[] memo;
    public int lengthOfLIS(int[] nums) {
        memo = new int[nums.length];
        int ret = 0;
        for(int i = 0; i < nums.length; i++) {
            ret = Math.max(ret, dfs(nums, i));
        }
        return ret;
    }
    public int dfs(int[] nums, int pos) {
        int ret = 1;
        if(memo[pos] != 0) return memo[pos];
        for(int i = pos + 1; i < nums.length; i++) {
            if(nums[i] > nums[pos]) {
                ret = Math.max(ret, dfs(nums, i) + 1);
            }
        }
        memo[pos] = ret;
        return ret;
    }
}